function fid = fid2_setupHMO(varargin)
% FID_SETUP Set up various parameters for PARSE FID
%
% FID_SETUP initializes various parameters and arrays, depending on the
% parameter components and values supplied in the structure PSEQ and returns
% the values in another structure FID that includes the PSEQ variables plus
% the calculated parameters.
%
% Note that the origin is the upper left corner.  x is the row variable and
% y is the column variable.

pseq = varargin{1};
Ncpus = varargin{2};
ffac = varargin{3};
% frno = varargin{4};
FIDR01 = (pseq.FR1+1i*pseq.FI1-pseq.dcoff);  % FID with DC offset correction
FIDR02 = (pseq.FR2+1i*pseq.FI2-pseq.dcoff);  % FID with DC offset correction
NF0 = length(pseq.FR1);
fid.delt = 1/pseq.sw;  % time increment
NF = NF0;  % adjusted length of FID
if (Ncpus > 1)
    NF = NF - mod(NF,Ncpus);
end

fid.sigwt=hammsig78Scart(pseq.krd,pseq.kpe);
fid.estwt=single(onesig78Scart(pseq.krd,pseq.kpe));

FIDR1 = (FIDR01.*exp(-1i*(pseq.phir)').*exp(2i*pi*pseq.offr*(1:NF)'*fid.delt));
FIDR2 = (FIDR02.*exp(-1i*(pseq.phir)').*exp(2i*pi*pseq.offr*(1:NF)'*fid.delt)); 
kss = pseq.krd+1i*pseq.kpe;
FIDR1=(fid.sigwt).'.*FIDR1;
FIDR2=(fid.sigwt).'.*FIDR2;
%fid.sig = FIDR.';% normalize outside routine to permit using single normalization constant
fid.sig1 = ffac*FIDR1.'./sum(abs(FIDR1));
fid.sig2 = ffac*FIDR2.'./sum(abs(FIDR1));

if (Ncpus > 1)
    fid.kx = reshape(real(kss),Ncpus,NF/Ncpus);
    fid.ky = reshape(imag(kss),Ncpus,NF/Ncpus);
else
    fid.kx = single(real(kss));
    fid.ky = single(imag(kss));
end
